﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace YoutubeVideo.MyClass
{
    class XmlHelper
    {
        public XmlHelper()
        {
        }
        public List<VideoItem> LoadList()
        {
            var xElem = XElement.Load("Data/Data.xml");

            var products =
                from elem in xElem.Descendants("Item")
                orderby elem.Attribute("Group").Value
                select new VideoItem
                {
                    Group = elem.Attribute("Group").Value,
                    Title = elem.Attribute("Title").Value,
                    Author = elem.Attribute("Author").Value,
                    YoutubeID = elem.Attribute("YoutubeID").Value,
                    Image = elem.Attribute("Image").Value
                };

            return products.ToList<VideoItem>();
        }
        public IEnumerable<VideoItem> LoadList(string key)
        {
            var xElem = XElement.Load("Data/Data.xml");

            var products =
                from elem in xElem.Descendants("Item")
                orderby elem.Attribute("Group").Value
                select new VideoItem
                {
                    Group = elem.Attribute("Group").Value,
                    Title = elem.Attribute("Title").Value,
                    Author = elem.Attribute("Author").Value,
                    YoutubeID = elem.Attribute("YoutubeID").Value,
                    Image = elem.Attribute("Image").Value
                };
            return products.ToList<VideoItem>();
        }
    }
}
